<template>
  <div>
    <yfuPTable ref="table" :param="tableParam" v-show="isShowTable"></yfuPTable>
    <yfuLookDialog ref="yfuLook" :param="lookParam" v-if="isShowLook" v-on:returnPreNoRefresh="returnPreNoRefresh"></yfuLookDialog>
  </div>
</template>
<style>
</style>
<script>
  import yfuPTable from '@/components/common/yfuPTable.vue'
  import {list, selectOne} from '@/view/website/api/contact.js'
  import getPermissionByMenuId from '@/utils/MenuPermissionUtils.js'
  import yfuLookDialog from '@/components/common/yfuLookDialog.vue'
  export default {
    components: {
      'yfuPTable': yfuPTable,
      'yfuLookDialog': yfuLookDialog
    },
    // 进入时初始化TABLE
    created () {
      let cThis = this
      getPermissionByMenuId(this.sessiongetJSON('user').id, this.menuId, function (permissionString) {
        cThis.permissions = permissionString
        cThis.tableParam.permissions = permissionString
      })
    },
    data () {
      let cThis = this
      return {
        // dialog状态
        dialogStatus: '',
        currentRow: {},
        isShowTable: true,
        isShowLook: false,
        isShowRichText: false,
        menuId: this.$route.query.id,
        isShowEdit: false,
        tableParam: {
          permissions: '',
          showBox: true,
          baseURL: process.env.BASE_API,
          url: list.url,
          urlParam: {
            hasCard: 1
          },
          showToolButton: true,
          toolButtonSpan: 1,
          toolButtons: [
          ],
          toolSearchSpan: 20,
          toolSearchItems: [
            {
              label: '姓名',
              prop: 'gwMessageName',
              type: 'input',
              span: 6
            }, {
              label: '手机',
              prop: 'gwMessageMobile',
              type: 'input',
              span: 6
            }, {
              label: '时间',
              prop: 'showTime',
              type: 'daterange',
              times: ['beginTime', 'endTime'],
              span: 6
            }
          ],
          operateRow: {
            width: '100px'
          },
          showOperateRow: true,
          operateButtons: [
            {
              operateFunction: function (row) {
                cThis.openLookDialog(row)
              },
              icon: 'eye_black',
              permission: '/tkContactLook'
            }
          ],
          rows: [
            {
              prop: 'gwMessageName',
              label: '姓名'
            },
            {
              prop: 'gwMessageMobile',
              label: '手机'
            },
            {
              prop: 'gwMessageEmail',
              label: '邮箱'
            },
            {
              prop: 'createTime',
              label: '创建时间'
            },
            {
              prop: 'gwMessageDesc',
              label: '内容'
            }
          ]
        },
        lookParam: {
          id: 0,
          url: selectOne.url,
          trs: [
            {
              tds: [
                {
                  prop: '姓名',
                  type: 'name',
                  colspan: 1
                },
                {
                  prop: 'gwMessageName',
                  type: 'default',
                  colspan: 1
                },
                {
                  prop: '手机',
                  type: 'name',
                  colspan: 1
                },
                {
                  prop: 'gwMessageMobile',
                  type: 'default',
                  colspan: 3
                }
              ]
            },
            {
              tds: [
                {
                  prop: '邮箱',
                  type: 'name',
                  colspan: 1
                },
                {
                  prop: 'gwMessageEmail',
                  type: 'default',
                  colspan: 1
                },
                {
                  prop: '创建时间',
                  type: 'name',
                  colspan: 1
                },
                {
                  prop: 'createTime',
                  type: 'default',
                  colspan: 1
                }
              ]
            },
            {
              tds: [
                {
                  prop: '详情',
                  type: 'name',
                  colspan: 1
                },
                {
                  prop: 'gwMessageDesc',
                  type: 'default',
                  colspan: 5
                }
              ]
            }
          ]
        }
      }
    },
    methods: {
      refreshTable () {
        this.$refs.table.refreshTable()
      },
      fmDataToRefreshTable () {
        this.refreshTable()
      },
      openDialog (row) {
        this.isShowEdit = true
        this.isShowTable = false
        this.isShowLook = false
        this.currentRow = row
      },
      openAddDialog () {
        this.isShowEdit = true
        this.isShowTable = false
        this.isShowLook = false
        this.currentRow = {}
      },
      fmModuleToRefreshTable () {
        this.refreshTable()
      },
      getDialogStatus () {
        return this.dialogStatus
      },
      openLookDialog (row) {
        this.isShowLook = true
        this.isShowTable = false
        this.isShowEdit = false
        this.lookParam.id = row.id
        this.currentRow = row
      },
      openRichTextDialog (row) {
        this.isShowRichText = true
        this.isShowTable = false
        this.isShowEdit = false
        this.currentRow = row
      },
      returnPre () {
        this.isShowEdit = false
        this.isShowTable = true
        this.isShowLook = false
        this.isShowPlatform = false
        this.isShowRichText = false
        this.refreshTable()
      },
      returnPreNoRefresh () {
        this.isShowEdit = false
        this.isShowTable = true
        this.isShowLook = false
        this.isShowPlatform = false
        this.isShowRichText = false
      }
    }
  }
</script>
